#pragma once

#include "AdvancedOgreFramework.h"
#include "TerrainEx.h"

using namespace Ogre;
#define CAM_HEIGHT 2  

class CameraEx
{

private:
	SceneManager*							m_pSceneMgr;
	Camera*									m_pCamera;
	TerrainEx*								m_pTerrain;
	SceneNode*								m_pBodyNode;
	SceneNode*								m_pCameraPivotNode;
	SceneNode*								m_pCameraGoalNode;
	SceneNode*								m_pCameraNode;
	Real									m_rPivotPitch;	
	size_t									m_fType;
	Real									m_rMoveScale;
	Real									m_rMoveSpeed;
	
	size_t									m_fControlModel;	// control model 1 :Object Inspection Camera , 0 : unrestrained

	Ogre::Vector3							m_vTranslateVector;

	Entity*									m_pCameraCollisionBox;
	SceneNode*								m_pCameraCollisionNode;
	std::vector<CameraCollision>			m_vAxisaligneboxList;
	
	
	Ogre::Radian							m_rCamYaw;
	bool									m_bCamCollision;
	Ogre::Radian							m_rperCamYaw;

	static int								m_nCount;

protected:
	void	collisionObject(CameraCollision* box);
	void	forEachAxisalignebox();
public:
	CameraEx(SceneManager* mSceneMgr, Camera* came=0, TerrainEx* terrain=0);
	~CameraEx(void);
	void updateCamera(Real deltaTime, Ogre::Vector3 traget);
	void updateCameraGoal(Real deltaYaw, Real deltaPitch, Real deltaZoom);
	void injectMouseMove(const OIS::MouseEvent& evt);
	void injectMouseDown(const OIS::MouseEvent& evt, OIS::MouseButtonID id);
	void injectKeyDown(const OIS::KeyEvent& evt);
	void injectKeyUp(const OIS::KeyEvent& evt);
	void injectKeyMoveCamera();


	void	addAlignedBox(CameraCollision box)
	{
		if (!box.AABB.isNull())
		{
			m_vAxisaligneboxList.push_back(box);	
		}else
		{
			box.AABB		= Ogre::AxisAlignedBox(0, 0, 0, 0, 0,0);
			box.bCollision	= false;
			m_vAxisaligneboxList.push_back(box);
		}

	}

	int getControlModel()
	{
		return m_fControlModel;
	}

	void setControlModel(int mode)
	{
		 m_fControlModel = mode;
	}

};
